//
//  SKCollectionCell.swift
//  AutoLayout
//
//  Created by linhan on 16/3/3.
//  Copyright © 2016年 linhan. All rights reserved.
//

import Foundation
import UIKit

class SWHistoryCollectionCell: UICollectionViewCell
{
    var indexPath:IndexPath?
    {
        didSet
        {
            layoutSubviews()
        }
    }
    
    private var _imageView:ImageLoader = ImageLoader()
    
    override init(frame: CGRect)
    {
        super.init(frame: frame)
        
        setup()
    }
    
    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setup()
    {
        contentView.backgroundColor = UIColor(hex: 0xf5f5f5)
        
        _imageView.frame = bounds
        contentView.addSubview(_imageView)
    }
    
    override func prepareForReuse()
    {
        super.prepareForReuse()
        //_change = true
    }
    
    override func layoutSubviews()
    {
        super.layoutSubviews()
        if let indexPath = indexPath
        {
            //_imageView.load(contentsOfFile: "")
            if let image = UIImage(named: "sbg_\(indexPath.row).jpg")
            {
                let scale:CGFloat = image.size.width / width
                let imageViewHeight:CGFloat = image.size.height  / scale
                _imageView.image = image
                _imageView.frame = CGRectMake(0, (height - imageViewHeight) * 0.5, width, imageViewHeight)
                
            }
            
            
        }
        
        
    }
    
    
    
}
